﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ExpensesClient.ViewModels
{
    public class ViewModelLocator
    {

        private static MainPageViewModel _mainPageViewModel;

        /// <summary>
        /// Gets the MainPageViewModel property.
        /// </summary>
        public static MainPageViewModel MainPageViewModelStatic
        {
            get
            {
                if (_mainPageViewModel == null)
                {
                    CreateMainPageViewModel();
                }

                return _mainPageViewModel;
            }
        }

        /// <summary>
        /// Gets the MainPageViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainPageViewModel MainPageViewModel
        {
            get
            {
                return MainPageViewModelStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the MainPageViewModel property.
        /// </summary>
        public static void ClearMainPageViewModel()
        {
            _mainPageViewModel.Cleanup();
            _mainPageViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to create the MainPageViewModel property.
        /// </summary>
        public static void CreateMainPageViewModel()
        {
            if (_mainPageViewModel == null)
            {
                _mainPageViewModel = new MainPageViewModel();
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
            ClearMainPageViewModel();
        }
    }
}
